<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>管理员管理用户</title>
<link rel="stylesheet"
	href="https://fonts.googleapis.com/css?family=Roboto:400,700" />
<link rel="stylesheet" href="../css/fontawesome.min.css" />
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/templatemo-style.css">
</head>
<script src="../js/jquery-1.7.2.js"></script>
<script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
<script type="text/javascript">

		function ManEditUserAjax(){
			var username=document.getElementById("na").value;
			var sex=document.getElementById("se").value;
			var age=document.getElementById("ag").value;
			var telephone=document.getElementById("te").value;
            var username_md5 = md5(username);

    		let re = new RegExp("\s?" + "user_id" + "=([^;]+)(;|$)")
    		var user_id=document.cookie.match(re)[1];
    		
          
            $.ajax({
	                url: "http://localhost:8080/voting-system/updateUser",
	                type: "post",
	                success:function (data) {
	                   if(data.updateUser==false){
	                        alert("修改失败！")
	                   }else{
	                        alert("修改成功！")
	                   }
	                },
	                dataType: "json",
	                data:{user_id:user_id, username:username, sex:sex, age:age, telephone:telephone, username_md5:username_md5}
	        });
	        
		}
</script>
<body id="reportsPage">
	<div class="" id="home">
		<nav class="navbar navbar-expand-xl">
			<div class="container h-100">
				<h1 class="tm-site-title mb-0">用户管理</h1>

				<button class="navbar-toggler ml-auto mr-0" type="button"
					data-toggle="collapse" data-target="#navbarSupportedContent"
					aria-controls="navbarSupportedContent" aria-expanded="false"
					aria-label="Toggle navigation">
					<i class="fas fa-bars tm-nav-icon"></i>
				</button>

				<div class="collapse navbar-collapse" id="navbarSupportedContent">
					 <ul class="navbar-nav mx-auto h-100">
            <li class="nav-item">
              <a class="nav-link" href="result.jsp">
                <i class="fas fa-tachometer-alt"></i> 投票结果
                <span class="sr-only">(current)</span>
              </a>
            </li>
            <li class="nav-item dropdown">
              <a
                class="nav-link active"
                href="update.html">
                <i class="far fa-file-alt"></i>
                <span>用户管理 </span>
              </a>
            </li>
            <li class="nav-item">
              <a class="nav-link dropdown-toggle" href="manage.html">
                <i class="fas fa-shopping-cart"></i> 投票管理
              </a>
            </li>

            <li class="nav-item">
              <a class="nav-link" href="center.html">
                <i class="far fa-user"></i> 个人中心
              </a>
            </li>
           
          </ul>
					<ul class="navbar-nav">
						<li class="nav-item"><a class="nav-link d-block"
							href="login.html"> <b>退出登录</b>
						</a></li>
					</ul>
				</div>
			</div>
		</nav>
		<div class="container mt-5" style="position: relative; left: 170px;">

			<div class="tm-block-col tm-col-account-settings">
				<div class="tm-bg-primary-dark tm-block tm-block-settings">
					<h2 class="tm-block-title">账号设置</h2>
					<form action="" class="tm-signup-form row">
						<div class="form-group col-lg-6">
							<label for="name">用户名</label> <input name="na" type="text" id="na"
								class="form-control validate">
						</div>

						<div class="form-group col-lg-6">
							<label for="password">性别</label> <input name="se" type="text" id="se"
								class="form-control validate">
						</div>
						<div class="form-group col-lg-6">
							<label for="password2">年龄</label> <input name="ag" type="text" id="ag"
								class="form-control validate">
						</div>
						<div class="form-group col-lg-6">
							<label for="phone">电话</label> <input name="te" type="text" id="te"
								class="form-control validate">
						</div>

						<div class="col-12">
							<button type="button" onclick="ManEditUserAjax()"
								class="btn btn-primary btn-block text-uppercase mb-3">
								确认修改</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	</div>


</body>
</html>
